package com.yang.cplibrary.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class CaffeineConfig {

    @Bean
    public Cache<String, String> caffeineCache() {
        return Caffeine.newBuilder().initialCapacity(1024)
                        .maximumSize(2000L)
                        // 缓存 5 分钟移除
                        .expireAfterWrite(5L, TimeUnit.MINUTES)
                        .build();
    }
}
